package org.dromara.system.api.feign.fallback;

import cn.hutool.http.HttpStatus;
import lombok.extern.slf4j.Slf4j;
import org.dromara.common.core.domain.R;
import org.dromara.system.api.feign.SystemPermissionClient;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.Set;

/**
 * @author: zhou shuai
 * @date: 2025/7/12 16:07
 * @version: v1
 */
@Slf4j
@Component
public class SystemPermissionClientFallBack implements FallbackFactory<SystemPermissionClient> {
    @Override
    public SystemPermissionClient create(Throwable throwable) {
        log.error("SystemPermissionClientFallBack, cause:{}", throwable.getMessage());
        return new SystemPermissionClient() {

            @Override
            public R<Set<String>> getRolePermission(Long userId) {
                return R.fail(HttpStatus.HTTP_BAD_METHOD, throwable.getLocalizedMessage());
            }

            @Override
            public R<Set<String>> getMenuPermission(Long userId) {
                return R.fail(HttpStatus.HTTP_BAD_METHOD, throwable.getLocalizedMessage());
            }

        };
    }
}
